//
//  WMUtils.m
//  WholeMusic
//
//  Created by quanxiong on 2018/2/24.
//  Copyright © 2018年 quanxiong. All rights reserved.
//

#import "WMUtils.h"

@implementation WMUtils

@end


extern wc_force_inline void fp_dispatch_main_sync_safe(dispatch_block_t block) {
    if (!block) {
        return;
    }
    if ([NSThread isMainThread]) {
        block();
    } else {
        dispatch_sync(dispatch_get_main_queue(), block);
    }
}

extern wc_force_inline void fp_dispatch_main_async_safe(dispatch_block_t block) {
    if (!block) {
        return;
    }
    if ([NSThread isMainThread]) {
        block();
    } else {
        dispatch_async(dispatch_get_main_queue(), block);
    }
}

extern wc_force_inline void fp_dispatch_global_async_if_need(dispatch_block_t block) {
    if (!block) {
        return;
    }
    if ([NSThread isMainThread]) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
    } else {
        block();
    }
}

extern wc_force_inline void fp_dispatch_global_then_dispatch_main_queue(dispatch_block_t global_block, dispatch_block_t main_block) {
    if (!global_block || !main_block) {
        return;
    }
    fp_dispatch_global_async_if_need(^{
        global_block();
        fp_dispatch_main_async_safe(main_block);
    });
}
